
$(function () {
    //获取页面的表单对象
    $("#uPhone").on("blur",function () {
        var tester = /^1[3|4|5|8][0-9]\d{4,8}$/gi;
        if (tester.test($(this).val())) {
            $("#uPhone_judge").css("display","none").text("");
        } else {
            $("#uPhone_judge").css("display","inline-block").text("请输入正确格式的手机号！");
        }
    });
    function Confirm_code (){
        var arr = [0,1,2,3,4,5,6,7,8,9,"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"];
        var arr1 = [];
        for(var i = 0;i<4;i++){
            arr1.push(arr[parseInt(Math.random()*arr.length)]);
        }
        var str = ""+arr1[0]+arr1[1]+arr1[2]+arr1[3];
        $("#uConfirm_code").text(str);
        return str;
    }
    Confirm_code();
    $("#switch").on("click",function(){
        Confirm_code();
    });
    $("#uConfirm").on("blur",function () {
        if ($("#uConfirm").val()==$("#uConfirm_code").text()) {
            $("#uConfirm_judge").css("display","none").text("");
        } else {
            $("#uConfirm_judge").css("display","inline-block").text("验证码不正确！");
        }
    });
    $("#uText").on("blur",function () {
        if ($("#uText").val()!="") {
            $("#uText_judge").css("display","none").text("");
        } else {
            $("#uText_judge").css("display","inline-block").text("验证码不能为空");
        }
    });
    $("#uName").on("blur",function () {
        var tester = /^[a-zA-Z0-9_]{3,16}$/gi;
        if (tester.test($(this).val())) {
            $("#uName_judge").css("display","none").text("");
        } else {
            $("#uName_judge").css("display","inline-block").text("用户名为3～16个字符");
        }
    });
    $("#uPwd").on("focus",function () {
        $("#uPwdDeg").css("display","block");
    });
    $("#uPwd").on("blur",function () {
        $("#uPwdDeg").css("display","none");
        if ($(this).val().length<=16&&$(this).val().length>=3) {
            $("#uPwd_judge").css("display","none").text("");
        } else {
            $("#uPwd_judge").css("display","inline-block").text("密码为3～16个字符");
        }
    });
    $("#uPwd").on("keyup",function () {
        var strong = /^(?![a-zA-z]+$)(?!\d+$)(?![~!@#\$%^&*\(\)\{\};,.\?\/'"]+$)(?![a-zA-z\d]+$)(?![a-zA-z~!@#\$%^&*\(\)\{\};,.\?\/'"]+$)(?![\d~!@#\$%^&*\(\)\{\};,.\?\/'"]+$)[a-zA-Z\d~!@#\$%^&*\(\)\{\};,.\?\/'"]+$/gi;
        var middle1 = /^(?!\d+$)(?![a-zA-Z]+$)[a-zA-Z\d]+$/gi;
        var middle2 = /^(?![a-zA-Z]+$)(?![@#$%^&]+$)[a-zA-Z@#$%^&]+$/gi;
        var middle3 = /^(?!\d+)(?![@#$%^&]+$)[\d@#$%^&]+$/gi;
        var weak = /^(?:\d+|[a-zA-Z]+|[!@#$%^&*]+)$/gi;
        var deg = 0;
        if($("#uPwd").val().match(weak)){
            deg = 1;
        }
        if($("#uPwd").val().match(middle1)||$("#uPwd").val().match(middle2)||$("#uPwd").val().match(middle3)){
            deg = 2;
        }
        if($("#uPwd").val().match(strong)){
            deg = 3;
        }
        if(deg == 1){
            $("#deg1").css("background","red");
            $("#deg2").css("background","grey");
            $("#deg3").css("background","grey");
        }
        if(deg == 2 && $("#uPwd").val().length>=7){
            $("#deg1").css("background","blue");
            $("#deg2").css("background","blue");
            $("#deg3").css("background","grey");
        }
        if(deg == 2 && $("#uPwd").val().length<7){
            $("#deg1").css("background","red");
            $("#deg2").css("background","grey");
            $("#deg3").css("background","grey");
        }
        if(deg == 3 && $("#uPwd").val().length>=11){
            $("#deg1").css("background","green");
            $("#deg2").css("background","green");
            $("#deg3").css("background","green");
        }
        if(deg == 3 && $("#uPwd").val().length<11){
            $("#deg1").css("background","blue");
            $("#deg2").css("background","blue");
            $("#deg3").css("background","grey");
        }
    });
    $("#ucPwd").on("blur",function () {
        if ($("#ucPwd").val() == $("#uPwd").val()) {
            $("#ucPwd_judge").css("display","none").text("");
        }else{
            $("#ucPwd_judge").css("display","inline-block").text("确认密码错误");
        }
    });

    $("#btn").on("click", function (){
        if($("#Entente").prop("checked")
            &&$("#uPhone").val()!=""
            &&$("#uPwd").val()!=""
            &&$("#uConfirm").val()!=""
            &&$("#uText").val()!=""
            &&$("#uName").val()!=""
            &&$("#ucPwd").val()!=""
            &&$("#uPhone_judge").val()==""
            &&$("#uPwd_judge").val()==""
            &&$("#uConfirm_judge").val()==""
            &&$("#uText_judge").val()==""
            &&$("#uName_judge").val()==""
            &&$("#ucPwd_judge").val()==""){
            $.ajax({
                //请求地址
                url:"http://localhost/PHP/Epet_register.php",
                //请求方式
                type: "post",
                //
                data: $("#register").serialize(),
                success: function (result) {
                    console.log(JSON.parse(result).status);
                    if(JSON.parse(result).status==1){
                        alert("注册成功！");
                        window.location.href="http://localhost:63342/mycode/html/Epet_login_page.html";
                    }else{
                        alert("用户名或手机号码已被占用！");
                    }
                }
            })
        }else{
            alert("请重新核对信息格式！")
        }
    })
});
